package com.hw.paltfrom.controller.system;

import com.hw.paltfrom.pack.ResponseResult;
import com.hw.paltfrom.pojo.HwBaseOverrunstation;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.service.system.UserLoginService;
import com.hw.paltfrom.utils.*;
import com.hw.paltfrom.vo.BaseOverrunstationVO;
import com.hw.paltfrom.vo.LoginRequestVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 *用户登陆
 * 刘郴
 * 2019年11月6日15:06:04
 */

@RestController
@RequestMapping(value = "/user")
public class UserLoginController {

    @Autowired
    private UserLoginService userLoginService;


/*
    @RequestMapping(value = "/add")
    public Map<String, Object> addUser(LoginRequestVO loginRequestVO) {
        //验证前端信息非空
        Boolean flag = VerifyUtil.verifyParams(loginRequestVO);
        //返回错误提示
        if (!flag) {
            return ResponseResult.fail(HWSystemCode.PARAMS_ERROR);
        }
        return userLoginService.addUser(loginRequestVO);

    }*/

//登录
    @RequestMapping(value = "/login")
    public Map<String, Object> loginByPassWord(LoginRequestVO loginRequestVO) {
        if(loginRequestVO == null || StringUtils.isBlank(loginRequestVO.getfAccount())){
        	return ResponseResult.fail(HWSystemCode.AUTH_USERNAME_NONE);
        }
        if(StringUtils.isBlank(loginRequestVO.getfPassword())){
        	return ResponseResult.fail(HWSystemCode.AUTH_PASSWORD_NONE);
        }

        Map<String, Object> result = userLoginService.loginByPassword(loginRequestVO);
        /*Object object = result.get("code");
        if(object.equals(HWSystemCode.SUCCESS.code())){
        	String token = RandomNumberUtil.getNumber();
        	RedisUtil redis = SpringUtil.getBean(RedisUtil.class);
        	redis.set("token"+result.get("fAccount"), token);
        	result.put("token", token);
        }*/
        return result;

    }


//退出
    @RequestMapping(value = "/logout")
    public Map<String, Object> logout(String fAccount) {
        //返回错误提示
        RedisUtil redis = SpringUtil.getBean(RedisUtil.class);
        redis.del("loginToken:"+fAccount);
        return ResponeResultUtil.success(HWSystemCode.LOG_OUT);
    }

    /**
     * 站点值班管理
     * @param fOverrunCode
     * @return  Station duty management
     * @date 11点53分
     */
    @RequestMapping(value = "/management")
    public Map<String, Object> StationDutyManagement(String fOverrunCode) {
        if (fOverrunCode!=null&&fOverrunCode!=""){
          return  userLoginService.StationDutyManagement(fOverrunCode);
        }
            return ResponeResultUtil.fail(HWSystemCode.PARAMS_ERROR);
    }

    /**
     * 站点值班修改
     * @param vo
     * @return  revampManagement
     * @date 11点53分
     */
    @RequestMapping(value = "/revamp")
    public Map<String, Object> revampManagement(BaseOverrunstationVO vo) {
        String fOverrunCode = vo.getfOverruncode();
        if (fOverrunCode!=null&&fOverrunCode!=""){
            return  userLoginService.revampStationDutyManagement(vo);
        }
        return ResponeResultUtil.fail(HWSystemCode.PARAMS_ERROR);
    }


}
